Skip to content

fix: stfc remove roles bug - #1605

Merged
ellen-wright merged 6 commits into
developfrom
1610-fix-stfc-remove-roles-bug
Jun 26, 2026
Merged

fix: stfc remove roles bug#1605
ellen-wright merged 6 commits into
developfrom
1610-fix-stfc-remove-roles-bug

Conversation

@ellen-wright

Copy link
Copy Markdown
Contributor

Description

refs: #UserOfficeProject/issue-tracker#1610

Fixes bug that stopped the removal of the all UOS given roles.

Now when removing a role if it is the last role given in UOS and not from STFC UOWS then all UOS roles are removed from the role_user table for that user and only roles from UOWS are left.

Motivation and Context

When wanting to remove all roles given in the UI and not from UOWS there was a bug where the role would not be deleted as it was the last roles associated with that user in the role_user table, however an STFC user will always have roles given by UOWS and therefore can have all UOS given roles removed without error.

How Has This Been Tested

Fixes

Changes

Depends on

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@ellen-wright
ellen-wright requested a review from a team as a code owner June 24, 2026 14:10
@ellen-wright
ellen-wright requested review from a team, Bhaswati1148, ChongJiaChua, deepaksftc and mutambaraf and removed request for a team, Bhaswati1148 and ChongJiaChua June 24, 2026 14:10

@mutambaraf mutambaraf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some few comments.

Comment on lines +478 to +480
async removeUserRoles(id: number): Promise<void> {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not mocking any thing here

Comment on lines +529 to +531
async removeUserRoles(id: number): Promise<void> {
throw new Error('Method not implemented.');
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to pass this to the super class or implement it.


if (newRolesToAssign.length > 0) {
if (newRolesToAssign.length == 0) {
postgresUserDataSource.removeUserRoles(id);

@mutambaraf mutambaraf Jun 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need await here

}

async removeUserRoles(id: number): Promise<void> {
return database.transaction(async (trx) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be missing await


async removeUserRoles(id: number): Promise<void> {
return database.transaction(async (trx) => {
await trx<RoleUserRecord>('role_user').where('user_id', id).del();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may leave some one with out any assigned role do not we need to leave at least the user role

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only remove the roles assigned in the role)user table all UOWS assigned roles will still be there and we give everyone at least one role from UOWS right?

@ellen-wright
ellen-wright merged commit 4c664ac into develop Jun 26, 2026
49 of 51 checks passed
@ellen-wright
ellen-wright deleted the 1610-fix-stfc-remove-roles-bug branch June 26, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants